<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>评分组件</title>
		<link rel="stylesheet" href="../../statics/layui/css/layui.css">
		<link href="../../css/criterion/main.css" rel="stylesheet" type="text/css" />
		<link href="../../css/criterion/iconfont.css" rel="stylesheet" type="text/css" />
		<link href="../../css/criterion/test.css" rel="stylesheet" type="text/css" />
	</head>

	<body>
		<div class="main">
			<!--nr start-->
			<div class="test_main">
				<!--<div class="layui-card-header">
					<span class="layui-col-md-offset11 layui-col-sm-offset11 layui-col-xs-offset11">
						<button type="button" id="back" title="返回" class="layui-btn layui-btn-normal layui-btn-xs" onclick="javascript:window.history.back(-1);"><i class="layui-icon">&#xe65c;</i>返回</button>
						<button type="button" id="refresh" title="刷新" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon layui-icon-refresh"></i></button>
					</span>
				</div>-->
				<div class="test">
					<form action="" method="post">
						<div class="test_title">
							<label><input type="button" name="refresh" id="refresh" value="刷新"></label>
							<font><input type="button" name="tijiao" value="提交" id="t_submit"></font>
						</div>
						<!--<div class="test_content">
						</div>-->
						<div class="test_content_nr" id="addEvacontents">
							<!--<ul id="addEvacontent">
							</ul>-->
						</div>
					</form>
				</div>
			</div>
			<!--nr end-->
			<div class="foot"></div>
		</div>
		<script src="../../statics/layui/layui.js"></script>
		<script src="../../statics/jquery/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../statics/lay/system/admin/public.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../statics/lay/system/admin/public_eva.js" type="text/javascript" charset="utf-8"></script>
		<script>
			layui.use(['rate', 'layer'], function() {
				var rate = layui.rate;
				var layer = layui.layer;
				var $ = layui.jquery;

				var createdata = new HashMap(); //存数据准备提交
				var ty_length = 0; //后台题数
				var isum = 1;
				var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
				var tId = getUrlParam("tId"); // 获取上一页面传来的tid
				var cId = getUrlParam("cId"); // 获取上一页面传来的cid
				layer.load();
				setTimeout(function() {
					layer.closeAll('loading');
				}, 800);
				initData()

				// 请求 题目数据
				function initData() {
					$.ajax({
						type: "get",
						url: IP + "/api/teacher_eav/evaluate/myselfeva",
						async: false,
						success: function(data) {
							layer.closeAll('loading');
							addEvaContent(data);
							ty_length = $('.test_content_nr_main').length; //获取页面实际添加长度
						}
					});
				}
				// 发送数据到后台
				function forwordData(data) {
					$.ajax({
						type: "post",
						url: IP + "/api/teacher_eav/teacherLogin",
						data: JSON.stringify(data),
						dataType: "json",
						async: false,
						success: function(data) {
							layer.msg("提交成功", {
								offset: ['50%'],
								time: 1000 //2秒关闭（如果不配置，默认是3秒）
							}, function() {
								parent.layer.close(index);
							});
						}
					});
				}


				//提交评价
				$("#t_submit").on('click', function() {
					var t = $('form').serializeArray();
					$.each(t, function() {
						createdata.put(parseInt(this.name), parseInt(this.value));
					});
					if(createdata.size() < ty_length) {
						layer.msg('<a style="color:red">你 尚 未 评 价 完 </a>', {
							icon: 2
						});
					} else {
						var submitNuber = [];
						var keys = createdata.keySet();
						for(var i = 0; i < keys.length; i++) {
							var value = createdata.get(keys[i]);
							submitNuber.push({
								tId: keys[i],
								value: value
							})
						}
						var data = {
							cId: cId,
							tId: tId,
							scoresT: JSON.stringify(submitNuber)
						}
						//发送请求
						forwordData(data);
					}
				})

				//	动态添加页面
				function addEvaContent(data) {
					GetDataEva({
						children: data
					}, null);
					$('#addEvacontents').append(menus);
				}
			});

			function HashMap() {
				//定义长度  
				var length = 0;
				//创建一个对象  
				var obj = new Object();

				/** 
				 * 判断Map是否为空 
				 */
				this.isEmpty = function() {
					return length == 0;
				};

				/** 
				 * 判断对象中是否包含给定Key 
				 */
				this.containsKey = function(key) {
					return(key in obj);
				};

				/** 
				 * 判断对象中是否包含给定的Value 
				 */
				this.containsValue = function(value) {
					for(var key in obj) {
						if(obj[key] == value) {
							return true;
						}
					}
					return false;
				};

				/** 
				 *向map中添加数据 
				 */
				this.put = function(key, value) {
					if(!this.containsKey(key)) {
						length++;
					}
					obj[key] = value;
				};

				/** 
				 * 根据给定的Key获得Value 
				 */
				this.get = function(key) {
					return this.containsKey(key) ? obj[key] : null;
				};

				/** 
				 * 根据给定的Key删除一个值 
				 */
				this.remove = function(key) {
					if(this.containsKey(key) && (delete obj[key])) {
						length--;
					}
				};

				/** 
				 * 获得Map中的所有Value 
				 */
				this.values = function() {
					var _values = new Array();
					for(var key in obj) {
						_values.push(obj[key]);
					}
					return _values;
				};

				/** 
				 * 获得Map中的所有Key 
				 */
				this.keySet = function() {
					var _keys = new Array();
					for(var key in obj) {
						_keys.push(key);
					}
					return _keys;
				};

				/** 
				 * 获得Map的长度 
				 */
				this.size = function() {
					return length;
				};

				/** 
				 * 清空Map 
				 */
				this.clear = function() {
					length = 0;
					obj = new Object();
				};
			}
		</script>
	</body>

</html>